package cn.vc.content.controller.article;

import cn.vc.auth.entity.po.VUser;
import cn.vc.basicmodule.entity.Result;
import cn.vc.content.service.article.ArticleCoinsService;
import cn.vc.content.service.article.ArticleService;
import cn.vc.content.util.SecurityUtil;
import cn.vc.wallet.feign.clients.WalletClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/articlecoins")
//@PreAuthorize("hasAnyAuthority('ordinary')")
public class ArticleCoinsController {
    @Autowired
    private ArticleService articleService;
    @Autowired
    private ArticleCoinsService articleCoinsService;
    @Autowired
    private HttpServletRequest request;
    @Autowired
    private WalletClient walletClient;


    /**
     * <h2>投币视频</h2>
     * @param id
     * @return
     */
    @PostMapping("/{id}/{coins}")
    public Result<?> like(@PathVariable("id") Long id, @PathVariable("coins") Long coins) {
        VUser myUser = SecurityUtil.getUser();
        if (myUser==null) return new Result<>(0);
        boolean bo = articleCoinsService.coins(id, myUser.getId(), coins);
        if (bo) {
            walletClient.coinCasting(myUser.getId());
            articleService.coins(id, 1);
        }
        return new Result<>(bo);
    }
}
